package com.fly.common.utils;

import freemarker.template.SimpleSequence;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by SWan on 2017/4/6.
 */
public class SortMethod implements TemplateMethodModelEx {

    public Object exec(List list) throws TemplateModelException {

        SimpleSequence arg0 = (SimpleSequence)list.get(0);
        List<BigDecimal> bigDecimals = arg0.toList();
        Collections.sort(bigDecimals, new Comparator<BigDecimal>() {
            public int compare(BigDecimal o1, BigDecimal o2) {
                System.out.println("o1:" + o1.intValue());
                System.out.println("o2:" + o2.intValue());
                return o1.intValue() - o2.intValue();//升序
            }
        });
        return bigDecimals;
    }
}
